package ru.inse.web;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;

import ru.inse.core.service.dict.ICityService;
import ru.inse.web.module.InseModule;


public class ControllerServiceTracker
    extends ServiceTracker<ICityService, ICityService>
{
    private InseModule inseModule;

    public ControllerServiceTracker(BundleContext context, InseModule inseModule)
    {
        super(context, ICityService.class, null);
        this.inseModule = inseModule;
    }

    public ICityService addingService(ServiceReference<ICityService> reference)
    {
        ICityService cityService = context.getService(reference);
        inseModule.setCityService(cityService);
        return cityService;
    }

    public void removedService(ServiceReference<ICityService> reference,
        ICityService service)
    {
        super.removedService(reference, service);
        inseModule.setCityService(null);
    }
}